package com.gupao.jly521.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Jly
 * @date 2018/8/21  16:36
 */
public class BeanFactory {

    private BeanFactory() {
    }

    private static Map<String,Object> ioc = new ConcurrentHashMap<>();

    public static Object getBean(String className){
        if(!ioc.containsKey(className)){
            Object obj = null;
            try {
                obj = Class.forName(className).newInstance();
                ioc.put(className,obj);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return  obj;
        }else {
            return ioc.get(className);
        }
    }
}
